package com.carlinfo.shop.goods.pojo;

import java.io.Serializable;
import java.util.Date;

import com.alibaba.fastjson.JSONObject;
import com.carlinfo.shop.common.util.DateUtil;
import com.carlinfo.shop.users.pojo.AAdmins;
import com.carlinfo.shop.users.pojo.AAdminsEnum;

/**
 * 品牌的POJO
 * @author wangshMac
 */
public class AGoodsBrand implements Serializable
{
	private int id;
	private int adminsId;
	private String name;
	private String website;
	private String logoPath;
	private String content;
	private byte status;
	private Date createTime;
	private Date updateTime;
	private Date pubTime;
	
	/* 字符串的描述 */
	private String statusStr ; 

	/* 关联关系 */
	private AAdmins admins ; 
	
	public AAdmins getAdmins()
	{
		return admins;
	}

	public void setAdmins(AAdmins admins)
	{
		this.admins = admins;
	}

	public int getId()
	{
		return id;
	}

	public void setId(int id)
	{
		this.id = id;
	}

	public int getAdminsId()
	{
		return adminsId;
	}

	public void setAdminsId(int adminsId)
	{
		this.adminsId = adminsId;
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public String getWebsite()
	{
		return website;
	}

	public void setWebsite(String website)
	{
		this.website = website;
	}

	public String getLogoPath()
	{
		return logoPath;
	}

	public void setLogoPath(String logoPath)
	{
		this.logoPath = logoPath;
	}

	public String getContent()
	{
		return content;
	}

	public void setContent(String content)
	{
		this.content = content;
	}

	public byte getStatus()
	{
		return status;
	}

	public void setStatus(byte status)
	{
		this.status = status;
	}

	public Date getCreateTime()
	{
		return createTime;
	}

	public void setCreateTime(Date createTime)
	{
		this.createTime = createTime;
	}

	public Date getUpdateTime()
	{
		return updateTime;
	}

	public void setUpdateTime(Date updateTime)
	{
		this.updateTime = updateTime;
	}

	public Date getPubTime()
	{
		return pubTime;
	}

	public void setPubTime(Date pubTime)
	{
		this.pubTime = pubTime;
	}
	
	public String getStatusStr()
	{
		/*状态:0:禁用;1:启用*/
		AGoodsBrandEnum[] brandEnums = AGoodsBrandEnum.values() ; 
		for (int i = 0; i < brandEnums.length; i++)
		{
			AGoodsBrandEnum brandEnum = brandEnums[i];
			/*
			 * adminsEnum.toString():枚举项
			 * */
			if(brandEnum.toString().startsWith("STATUS"))
			{
				if(this.status == brandEnum.getStatus())
				{
					this.statusStr = brandEnum.getInfo() ; 
					break ; 
				}
			}
		}
		return statusStr;
	}
	
	/**
	 * 把当前的对象变成json
	 * @return
	 */
	public JSONObject toJSON()
	{
		DateUtil dateUtil = new DateUtil() ; 
		JSONObject resultJSON = new JSONObject();
		
		resultJSON.put("id", this.getId());
		resultJSON.put("adminsId", this.getAdminsId());
		resultJSON.put("name", this.getName());
		resultJSON.put("website", this.getWebsite());
		resultJSON.put("logoPath", this.getLogoPath());
		resultJSON.put("content", this.getContent());
		resultJSON.put("status", this.getStatus());
		resultJSON.put("statusStr", this.getStatusStr());
		resultJSON.put("createTime", dateUtil.dateTimeToStr(this.getCreateTime()));
		resultJSON.put("updateTime", dateUtil.dateTimeToStr(this.getUpdateTime()));
		resultJSON.put("pubTime", dateUtil.dateTimeToStr(this.getPubTime()));
		
		/* 
		 * 要为当前对象的关联(管理员)也存储上json
		 * */
		if(this.admins != null)
		{
			resultJSON.put("adminsJSON", this.getAdmins().toJSON());
			resultJSON.put("admins_adminsName", this.getAdmins().getTrueName());
		}
		return resultJSON ; 
	}
}
